<template>
	<view class="container">
		<!-- 顶部可滑动标签页 -->
		<tab-scroll-view ref="tab_nav" :curAreaNum='curAreaNum' v-if="pageName=='history'"></tab-scroll-view>
		<view class="content" v-show="this.$store.state.areaObject.shebeibianhao != 0">
			<view class="searchBox">
				<!-- 按钮组切换 -->
				<view class="button-group">
					<button class="data-curve-btn" :class="{ 'active-btn': isCurveView }" @click="switchToCurve">
						数据曲线
					</button>
					<button class="history-data-btn" :class="{ 'active-btn': !isCurveView }" @click="switchToHistory">
						历史数据
					</button>
				</view>
			</view>
			<!-- 数据曲线页面 -->
			<view v-if="isCurveView">
				<Echarts :areaForm='areaForm'></Echarts>
			</view>
			<!-- 历史数据页面 -->
			<view v-else>
				<history-data ref="historyList"></history-data>
			</view>
		</view>
		<view v-if="this.$store.state.areaObject.shebeibianhao == 0 || this.$store.state.areaObject.shebeibianhao == ''"
			style="padding-top:60px;display: flex;justify-content: center;align-items: center;flex-direction: column;">
			<image src="../../static/null.png" mode="" style="magin:30px auto;height: 120px;width: 120px;"></image>
			<text>未绑定设备</text>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex';
	import {
		getDevHistoryData
	} from '../../api/index.js'
	import uCharts from '@/uni_modules/qiun-data-charts/js_sdk/u-charts/u-charts.js';
	import TabScrollView from '@/components/TabScrollView/TabScrollView.vue'
	import Echarts from '@/components/HistoryEcharts/HistoryEcharts.vue'
	import HistoryData from '@/components/HistoryView/HistoryView.vue';
	export default {
		components: {
			TabScrollView,
			Echarts,
			HistoryData
		},
		computed: {
			...mapState(['areaObject,'])
		},
		onShow() {
			console.log('history')
			this.pageName = 'history'
		},
		onHide() {
			this.pageName = ''
		},
		data() {
			return {
				// itemWidth: 0, //每个item的宽度
				// totalWidth: 100, //设置一个默认总宽度
				// scrollLeft: 0, //滑动距离
				activeTab: this.$store.state.curAreaNum,
				areaForm: {},
				isCurveView: true, // 控制是否显示数据曲线页面
				tableData: [],
				start_date: new Date().getTime(), // 绑定开始日期
				end_date: new Date().getTime(), // 绑定结束日期
				area_id: 8,
				pageName: ''
			};
		},

		// 下拉刷新
		onPullDownRefresh() {
			console.log('下拉刷新')
			setTimeout(() => {
				console.log('下拉刷新停止')
				uni.stopPullDownRefresh()
			}, 5500)
		},
		// 上拉加载
		onReachBottom() {
			console.log('上拉加载')
			// setTimeout(() => {
			// 	console.log('上拉加载停止')
			// 	uni.stopPullDownRefresh()
			// },5500
			this.$refs.historyList.paramsForm.page++
			this.$refs.historyList.getIrrigationHistory()
		},
		methods: {

			getData() {

			},

			switchToCurve() {
				this.isCurveView = true;
			},
			switchToHistory() {
				this.isCurveView = false;


			},


		}
	};
</script>

<style scoped lang="scss">
	/* 页面整体布局 */
	.container {}

	/* 智能控制栏 */
	.control-bar {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 40px;
		background-color: rgba(151, 151, 151, 0.12);
		margin-bottom: 15px;
		border-radius: 6px;
	}

	.control-bar text {
		font-size: 14px;
		color: #979797;
		font-weight: 300;
	}

	.arrow {
		left: 10px;
		position: relative;

		width: 10px;
		height: 10px;
	}

	/* 按钮组样式 */
	.button-group {
		display: flex;
		justify-content: space-around;
		margin: 10px 0;
	}

	.data-curve-btn {
		margin-right: 10px;
	}

	.content {
		padding: 46px 10px 20px;
	}

	.searchBox {
		position: fixed;
		top: 80px;
		width: 96%;
		z-index: 99;
		background: #fff;
	}

	.data-curve-btn,
	.history-data-btn {
		width: 100%;
		font-size: 16px;
		color: #064f9b;
		border-radius: 5px;
		text-align: center;
		background-color: #6ecff6;
	}

	/* 按钮选中时的样式 */
	.active-btn {
		background: #1c47e2;
		/* 选中时背景色 */
		color: white;
	}

	/* 日期选择器样式 */
	.date-picker {
		display: flex;
		align-items: center;
		justify-content: space-around;
		margin-bottom: 20px;
	}

	.search-btn {
		background: #409eff;
		color: #fff;
		border-radius: 5px;
		margin-left: 10px;
		height: 35px;
		line-height: 35px;
		font-weight: 300;
		font-size: 14px;
	}

	/* 数据表格样式 */
	.table {
		width: 100%;
	}

	.table-header {
		display: flex;
		background-color: #f5f5f5;
		padding: 10px 0;
	}

	.table-row {
		display: flex;
		background-color: #fff;

		padding: 10px 0;
		align-items: center;
	}

	.table-row:hover {
		background: rgba(0, 0, 0, 0.02);
	}

	.table-cell {
		flex: 1;
		text-align: center;
		font-size: 13px;
		font-weight: 300;
		flex-wrap: nowrap;
	}

	.table-row .table-cell:nth-last-child(-n + 2) {
		font-weight: 900;
	}

	.table-header .table-cell {
		font-weight: 400;
	}

	.info-header {
		font-size: 16px;
		font-weight: 400;
	}

	.info-content {
		display: flex;
		justify-content: space-around;
		font-size: 13px;
		font-weight: 300;
		margin-bottom: 10px;
	}

	.button-group-echats {
		display: flex;
		justify-content: space-around;
		margin-bottom: 20px;
		height: 24px;
		line-height: 24px;
		align-items: center;
	}

	.time-btn {
		background-color: #79BBFF;
		color: #fff;
		border-radius: 5px;
		border: none;
		font-size: 13px;
		flex: 1;

		text-align: center;
	}

	.time-btn:not(:last-child) {
		margin-right: 10px;
	}

	.active-btn {
		background: #1C47E2;

		color: #fff;
	}

	.charts-box {
		height: 300px;
		background-color: #fff;

	}
</style>